package com.basic.common.swagger2;

import lombok.Data;
import lombok.Getter;
import lombok.Setter;
import org.springframework.boot.context.properties.ConfigurationProperties;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

/**
 * swagger2 属性配置
 *
 * @author mall
 * @date 2018/11/18 9:17
 */
@Data
@ConfigurationProperties("swagger")
public class SwaggerProperties {
    /**
     * 是否开启swagger
     */
    private Boolean enabled = false;
    /**
     * 标题
     */
    private String title = "接口服务";

    /**
     * 描述
     */
    private String description = "接口服务接口文档";

    /**
     * 版本
     */
    private String version = "1.0";

    /**
     * 许可证
     */
    private String license = "";

    /**
     * 许可证URL
     */
    private String licenseUrl = "";

    /**
     * 服务条款URL
     */
    private String termsOfServiceUrl = "";

    /**
     * 连接器
     */
    private Contact contact = new Contact();

    /**
     * swagger解析的包路径
     */
    private String basePackage = "";

    /**
     * swagger解析的url规则
     */
    private List<String> basePath = new ArrayList<>();
    /**
     * 在basePath基础上需要排除的url规则
     */
    private List<String> excludePath = new ArrayList<>();

    /**
     * 分组文档
     */
    private Map<String, DocketInfo> docket = new LinkedHashMap<>();

    /**
     * host信息
     */
    private String host = "";

    /**
     * 全局参数配置
     */
    private List<GlobalOperationParameter> globalOperationParameters;

    @Setter
    @Getter
    public static class GlobalOperationParameter{
        /**
         * 参数名
         */
        private String name = "access_token";

        /**
         * 描述信息
         */
        private String description = "";

        /**
         * 指定参数类型
         */
        private String modelRef = "String";

        /**
         * 参数放在哪个地方:header,query,path,body.form
         */
        private String parameterType = "query";

        /**
         * 参数是否必须传
         */
        private String required = "true";
    }

    @Data
    public static class DocketInfo {
        /**
         * 标题
         */
        private String title = "";
        /**
         * 描述
         */
        private String description = "";
        /**
         * 版本
         */
        private String version = "";
        /**
         * 许可证
         */
        private String license = "";
        /**
         * 许可证URL
         */
        private String licenseUrl = "";
        /**
         * 服务条款URL
         */
        private String termsOfServiceUrl = "";

        private Contact contact = new Contact();

        /**
         * swagger会解析的包路径
         */
        private String basePackage = "com.basic";

        /**
         * swagger会解析的url规则
         */
        private List<String> basePath = new ArrayList<>();
        /**
         * 在basePath基础上需要排除的url规则
         */
        private List<String> excludePath = new ArrayList<>();

        private List<GlobalOperationParameter> globalOperationParameters;
    }

    @Data
    public static class Contact {
        /**
         * 联系人
         */
        private String name = "";
        /**
         * 联系人url
         */
        private String url = "";
        /**
         * 联系人email
         */
        private String email = "";
    }
}
